﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Abp.Auditing;
using Abp.Web.Models;
using FwProject.Authorization.Users;
using FwProject.BrandInfo;
using FwProject.BrandInfo.Dto;
using FwProject.Configuration;
using FwProject.Controllers;
using FwProject.ShoppingMall.BrandInfo;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;

namespace FwProject.Web.Shop.Controllers
{
    /// <summary>
    /// 品牌
    /// </summary>
    public class BrandsController : FwProjectControllerBase
    {
        private readonly IBrandInfoAppService _brandInfoAppService;
        private readonly IHostingEnvironment _env;
        private readonly IConfigurationRoot _appConfiguration;

        public BrandsController(IBrandInfoAppService brandInfoAppService, IHostingEnvironment env)
        {
             _env = env;
             _appConfiguration = _env.GetAppConfiguration();
            _brandInfoAppService = brandInfoAppService;
        }

        [DisableAuditing]
        public IActionResult Index()
        {
            ViewBag.ImageUrl = _appConfiguration["ImageUrl:url"].ToString();
            return View();
        }



        [HttpGet]
        [DisableAuditing]
        [WrapResult(false, false)]//关闭ABP的返回数据封装
        public async Task<IActionResult> GetBrandsData(int page, int limit, string keyword = "")
        {

            var data = await _brandInfoAppService.GetBrandLayerDataAsync(page, limit, keyword);
            return Json(data);
        }



        [DisableAuditing]
     
        public IActionResult Create()
        {
            return View();
        }

        public async Task<IActionResult> CreateBrand(BrandInput input)
        {
            var id = await _brandInfoAppService.CreateAsync(input);
            return Json(id);
        }
        [DisableAuditing]
        public async Task<IActionResult> Edit(Guid id)
        {
            var entity = await _brandInfoAppService.GetEnterDtoAsync(id);
           
            return View(entity);
        }
        public async Task<IActionResult> ModifyBrand(Guid id , BrandInput input)
        {
            var uid = await _brandInfoAppService.ModifyAsync(id, input);
            return Json("");
        }

        [HttpGet]
        public async Task<IActionResult> Delete(Guid id)
        {
            await _brandInfoAppService.DeleteAsync(id);
            return Json(id);
        }
        /// <summary>
        /// 上传图片
        /// </summary>
        /// <returns></returns>
        //[HttpPost]
        //public IActionResult UploadImage()
        //{
        //    return Json(base.UploadFile(_env, Request.Form.Files, Brand.TempFileUrlPrefix));
        //}
        [HttpPost]
        public IActionResult UpLoadBarand()
        {
            string FileServicePath = _appConfiguration["FileServicePath:TempBrand"].ToString();
            return Json(base.UploadFile(FileServicePath));
        }
    }
}